package org.jeecg.modules.flowable.demo.controller;

import org.jeecg.modules.flowable.demo.dto.DemoBizDTO;
import org.jeecg.modules.flowable.demo.entity.DemoBizEntity;
import org.jeecg.modules.flowable.demo.service.DemoBizService;
import org.jeecg.modules.flowable.vo.Result;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 流程引擎demo示例
 *
 * @author jiangtianyi
 */
@RestController
@RequestMapping("/FLOW/DEMO")
public class DemoBizController {

    private final DemoBizService demoBizService;

    @GetMapping("/LIST")
    public Result<List<DemoBizEntity>> queryAll() {
        return Result.OK(demoBizService.queryAll());
    }

    @GetMapping("/ONE/{id}")
    public Result<DemoBizEntity> queryOne(@PathVariable String id) {
        return Result.OK(demoBizService.queryOne(id));
    }

    @GetMapping("/DELETE/{id}")
    public Result<?> delete(@PathVariable String id) {
        demoBizService.delete(id);
        return Result.OK();
    }

    @PostMapping("/SAVE")
    public Result<?> save(@RequestBody DemoBizDTO demoBizDTO) {
        demoBizService.save(demoBizDTO);
        return Result.OK();
    }

    @PostMapping("/UPDATE")
    public Result<?> update(@RequestBody DemoBizEntity demoBizEntity) {
        demoBizService.update(demoBizEntity);
        return Result.OK();
    }

    public DemoBizController(DemoBizService demoBizService) {
        this.demoBizService = demoBizService;
    }
}
